home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 104 / MacAddict_104_2005-04.iso / Software / Internet & Communication / WordPress 1.2.2 freeware.dmg / wordpress / wp-comments-post.php < prev    next >
Encoding:
PHP Script  |  2004-12-16  |  3.3 KB  |  117 lines

  1. <?php
  2. require( dirname(__FILE__) . '/wp-config.php' );
  3.  
  4. function add_magic_quotes($array) {
  5.     foreach ($array as $k => $v) {
  6.         if (is_array($v)) {
  7.             $array[$k] = add_magic_quotes($v);
  8.         } else {
  9.             $array[$k] = addslashes($v);
  10.         }
  11.     }
  12.     return $array;
  13.  
  14. if (!get_magic_quotes_gpc()) {
  15.     $_POST   = add_magic_quotes($_POST);
  16.     $_COOKIE = add_magic_quotes($_COOKIE);
  17. }
  18.  
  19. $author = trim(strip_tags($_POST['author']));
  20. if ( preg_match('/&#[0-9]{3};/i', $author) )
  21.     die();
  22.  
  23. $email = trim(strip_tags($_POST['email']));
  24. if (strlen($email) < 6)
  25.     $email = '';
  26.  
  27. $url = trim(strip_tags($_POST['url']));
  28. $url = ((!stristr($url, '://')) && ($url != '')) ? 'http://'.$url : $url;
  29. if (strlen($url) < 7)
  30.     $url = '';
  31.  
  32. $comment = trim($_POST['comment']);
  33.  
  34. if ( preg_match('/&#[0-9]{3};/i', $comment) )
  35.     die();
  36.  
  37. $comment_post_ID = intval($_POST['comment_post_ID']);
  38. $user_ip = $_SERVER['REMOTE_ADDR'];
  39.  
  40.  
  41. $post_status = $wpdb->get_var("SELECT comment_status FROM $tableposts WHERE ID = '$comment_post_ID'");
  42.  
  43. if ( empty($post_status) ) {
  44.     // Post does not exist.  Someone is trolling.  Die silently.
  45.     die();
  46. } else if ( 'closed' ==  $post_status ) {
  47.     die( __('Sorry, comments are closed for this item.') );
  48. }
  49.  
  50. if ( get_settings('require_name_email') && ('' == $email || '' == $author) )
  51.     die( __('Error: please fill the required fields (name, email).') );
  52.  
  53. if ( '' == $comment )
  54.     die( __('Error: please type a comment.') );
  55.  
  56.  
  57. $now = current_time('mysql');
  58. $now_gmt = current_time('mysql', 1);
  59.  
  60.  
  61. $comment = balanceTags($comment, 1);
  62. $comment = format_to_post($comment);
  63. $comment = apply_filters('post_comment_text', $comment);
  64.  
  65. // Simple flood-protection
  66. $lasttime = $wpdb->get_var("SELECT comment_date FROM $tablecomments WHERE comment_author_IP = '$user_ip' ORDER BY comment_date DESC LIMIT 1");
  67. if (!empty($lasttime)) {
  68.     $time_lastcomment= mysql2date('U', $lasttime);
  69.     $time_newcomment= mysql2date('U', $now);
  70.     if (($time_newcomment - $time_lastcomment) < 10)
  71.         die( __('Sorry, you can only post a new comment once every 10 seconds. Slow down cowboy.') );
  72. }
  73.  
  74.  
  75. // If we've made it this far, let's post.
  76.  
  77. if(check_comment($author, $email, $url, $comment, $user_ip)) {
  78.     $approved = 1;
  79. } else {
  80.     $approved = 0;
  81. }
  82.  
  83. $wpdb->query("INSERT INTO $tablecomments 
  84. (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_approved) 
  85. VALUES 
  86. ('$comment_post_ID', '$author', '$email', '$url', '$user_ip', '$now', '$now_gmt', '$comment', '$approved')
  87. ");
  88.  
  89. $comment_ID = $wpdb->get_var('SELECT last_insert_id()');
  90.  
  91. if (!$approved) {
  92.     wp_notify_moderator($comment_ID);
  93. }
  94.  
  95. if ((get_settings('comments_notify')) && ($approved)) {
  96.     wp_notify_postauthor($comment_ID, 'comment');
  97. }
  98.  
  99. do_action('comment_post', $comment_ID);
  100.  
  101. setcookie('comment_author_' . $cookiehash, $author, time() + 30000000, COOKIEPATH);
  102. setcookie('comment_author_email_' . $cookiehash, $email, time() + 30000000, COOKIEPATH);
  103. setcookie('comment_author_url_' . $cookiehash, $url, time() + 30000000, COOKIEPATH);
  104.  
  105. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  106. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  107. header('Cache-Control: no-cache, must-revalidate');
  108. header('Pragma: no-cache');
  109. $location = get_permalink($comment_post_ID);
  110. if ($is_IIS) {
  111.     header("Refresh: 0;url=$location");
  112. } else {
  113.     header("Location: $location");
  114. }
  115.  
  116. ?>